define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/statics/index' + location.search,
                    // add_url: 'user/statics/add',
                    // edit_url: 'user/statics/edit',
                    // del_url: 'user/statics/del',
                    multi_url: 'user/statics/multi',
                    import_url: 'user/statics/import',
                    table: 'user_statics',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'total_money', title: __('Total_money'), operate: 'BETWEEN'},
                        {field: 'days', title: __('Days')},
                        {field: 'hasmoney', title: __('Hasmoney')},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        // {field: 'status', title: __('Status')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'release', //唯一标识、权限标识
                                    text: '释放', //按钮显示的文字，支持function
                                    title: '释放', //按钮显示的文字，支持function
                                    classname: 'btn btn-info btn-xs btn-ajax', //按钮的class，支持btn-dialog/btn-ajax/btn-addtabs
                                    confirm: '确定释放该订单？', //点击按钮后的确认框，支持function
                                    refresh: true, //操作完成后是否刷新列表
                                    url: 'user/Statics/release/id/{id}', //按钮的链接，支持使用{字段名}来占位替换，支持function
                                    disable: function (row) {
                                        if (row.status == 1) {
                                            return true;
                                        } else {
                                            return false;
                                        }
                                    },
                                    extend: '', //扩展的扩展属性，FastAdmin1.4.0+支持function
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
